﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BaiduMapArea
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            this.txtResult.Text = GetArea.GetPolygonArea(AddPoint(this.txtPoints.Text)).ToString();
        }

        dsArea.PointDataTable AddPoint(string s)
        {
            char[] delimiterChars = { ',', '，'};
            string[] points = SplitString(s, delimiterChars);
            dsArea.PointDataTable pts = new dsArea.PointDataTable();

            foreach (string p in points)
            {
                if (!IsNullOrEmpty(p))
                {
                    char[] delimiterChars1 = { ' ' };
                    string[] xy = SplitString(p.Trim(), delimiterChars1);
                    pts.Rows.Add(xy[0].Trim(), xy[1].Trim());
                }
            }
            
            return pts;
        }

        public static string[] SplitString(string value, char[] delimiterChars)
        {
            return value.Split(delimiterChars);
        }

        public static bool IsNullOrEmpty(string value)
        {
            return value == null || value.Trim() == string.Empty;
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.txtPoints.Text = "";
            this.txtResult.Text = "";
        }
    }
}
